/*
 * To change this template, choose Tools | Templates and open the template in
 * the editor.
 */
package goodenglish.infrastructure;

/**
 * 
 * @author 关攀攀 panpan_001@126.com
 */
public class TextParsing {

	/**
	 * 从字符串中提取单词
	 * 考虑-
	 * @param str
	 * @return
	 */
	public static String[] extractWordsFromString(String str) {
		String wordsAllStr = str.replaceAll("[^a-zA-Z']", " ").trim();
		return wordsAllStr.split(" ");
	}

	/**
	 * 判断字幕串中是否含有单词 [\\s\\S]*任意字符 ^\\w非字母 要考虑有空格分开的连词
	 * 
	 * @param enStr
	 * @param spell
	 * @return
	 */
	public static boolean containsWord(final String enStr, final String spell) {
		if (null == enStr) {
			return false;
		}
		if (spell.contains(" ") || spell.contains("　")) {
			String enStrNew = " " + enStr.replaceAll(" ", "").replaceAll("　", "") + " ";
			String spellNew = spell.replaceAll(" ", "").replaceAll("　", "");
			return enStrNew.contains(spellNew);
		} else {
			String str = " " + enStr + " ";
			return str.matches("[\\s\\S]*[^\\w]" + spell + "[^\\w][\\s\\S]*");
		}

	}
	// /**
	// * 把一个句子当中的单词替换成指定字符串
	// */
	// public static String replaceWord(String enStr, String word, String
	// replaceStr) {
	// return enStr.replaceAll(" " + word + " ", " " + replaceStr + " ");
	// }
}
